#pragma once
#include <pthread.h>
#include "Mutex.hpp"

namespace CondModule
{
    class Cond
    {
    public:
        Cond()
        {
            pthread_cond_init(&_cond, nullptr);
        }
        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }

        Cond(const Cond&) = delete;
        Cond& operator=(const Cond&) = delete;

        int wait(MutexModule::Mutex& mutex)
        {
            int n = pthread_cond_wait(&_cond, &mutex._mutex);
            return n;
        }
        int signal()
        {
            int n = pthread_cond_signal(&_cond);
            return n;
        }
        int broadcast()
        {
            int n = pthread_cond_broadcast(&_cond);
            return n;
        }
    private:
        pthread_cond_t _cond;
    };
}